<?php
// 我的资金
namespace app\home\controller;
use think\Db;
class Zijininfo extends HomeBase {

	public function getlist() {

		$uid = input('uid','0','intval');		// 用户id
		$order = input('order');	// 排序
		$page = input('page','1','intval');		// 当前页
		$row = input('row','10','intval');		// 每页显示数据

		if (!$uid) return json(array('status'=>0,'msg'=>'参数丢失'));

		// 排序
		if (empty($order)) $order = 'fftime desc';
		
		// 分页
		$start = ($page-1) * $row;

		$member = Db::name('member')->where('id',$uid)->field('sfid')->find();
		if (!$member || !$member['sfid']) return json(array('status'=>0,'msg'=>'用户信息丢失'));

		$total = Db::name('zijininfo')->where('sfid',$member['sfid'])->count('id');
		$list = Db::name('zijininfo')->where('sfid',$member['sfid'])->order($order)->limit($start,$row)->field('id,catid,year,month,ndate,bid')->select();

		if (empty($list)) return json(array('status'=>0,'msg'=>'暂无数据'));
		else {
			foreach ($list as &$value ) {
				$value['cate'] = Db::name('zijincat')->where('id',$value['catid'])->value('title');
				$value['fabu_danwei'] = Db::name('danwei')->where('id',$value['bid'])->value('bname');
				$value['fabu_time'] = time_nianyueri($value['ndate']);
			}
			return json(array('status'=>1,'info'=>$list,'count'=>$total));
		}
	}

	public function getdetail() {
		$id = input('id');
		$id = intval($id);
		$info = Db::name('zijininfo')->where('id',$id)->find();
		if (!$info)
			return json(array('status'=>0,'msg'=>'数据未找到'));
		return json(array('status'=>1,'info'=>$info));
	}

	//我的资金
	public function wozijin(){
		$uid=input('uid');
		$member=  Db::name('Member')->where('id',$uid)->field('sfid')->find();

		if($uid){

			$info['zongzijin']=Db::name('Zijininfo')->where('sfid',$member['sfid'])->field('price')->sum('price');
			$info['yearzijin']=Db::name('Zijininfo')->where('sfid',$member['sfid'])->field('price')->sum('price');
			$minfos=Db::name('Zijininfo')->where('sfid',$member['sfid'])->field('id,zmid,year,zhen,cun,price,fftime,month,danwei')->order('fftime DESC')->select();
			if($minfos){
				foreach ($minfos as $key => $value) {
					$minfos[$key]['zjmgtitle']=Db::name('Zijinmanage')->where('id',$value['zmid'])->value('title');
					$minfos[$key]['ishow']=1;
					$minfos[$key]['times']=time_yueri($value['fftime']);
				}

			}
			$info['zijinlist']=$minfos;

			$datas['status']=1;
			$datas['info']=$info;
		}else{
			$datas['status']=0; //没有获取到用户信息！
			$datas['info']='没有获取到用户信息！';
		}
		return json($datas);
	}
}